#include "sdbusClient.hpp"
#include <sdbus-c++/IConnection.h>
#include <sdbus-c++/IProxy.h>

sdbusClinet::sdbusClinet()
{

}

sdbusClinet::~sdbusClinet()
{
  if(workThread.joinable())
  {
    session->leaveEventLoop();
    workThread.join();
  }
}

void sdbusClinet::Boot()
{
  const char* interface="org.HBTY.ServerUI";
  session=sdbus::createSessionBusConnection();
  proxy=sdbus::createProxy(*session,"org.HBTY.ServerUI","/org/HBTY/ServerUI");
  proxy->uponSignal("MobileConnect").onInterface(interface).call([this](bool status){
    funcMobileConnectChange(status);
  });
  proxy->uponSignal("RecordStatus").onInterface(interface).call([this](bool status){
    funcRecordChange(status);
  });
  proxy->finishRegistration();

  workThread=std::thread([this](){
    session->enterEventLoop();
  });
}
